home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Add-Ons / MicroPhone / Open Mike™ / Open Mike™ 001 / Mike's Folder / Promptly I Said < prev    next >
Encoding:
Text File  |  1993-01-01  |  5.7 KB  |  79 lines  |  [TEXT/ttxt]

  1. PROMPTLY I SAID
  2.  
  3. Copyright © 1993 by Celestin Company
  4. All rights reserved.
  5.  
  6. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without permission in writing from the publisher. However, you are permitted to make copies of this work, printed or otherwise, as long as said copies are for your personal use only.
  7.  
  8. -------
  9.  
  10. How many times have your Watch Me scripts failed because the prompts you were looking for weren't there? Watch Me scripts are great, but they work well only when dealing with hosts that don't do fancy things during the log on process. For example, if your host gives you a prompt like this:
  11.  
  12.   login 04:58:22>
  13.  
  14. Watch Me will happily generate a script similar to this:
  15.  
  16. Dial Service "'My Host'"
  17. Wait for Text "'8:22>'"
  18. Send Text String "'bla bla bla^M'"
  19.  
  20. What if that number is the time of day? The next time you log onto the system, your prompt might be:
  21.  
  22.   login 06:19:13>
  23.  
  24. If you attempt to run your Watch Me generated script, it will fail. What you need to do is write a script that looks for the part of a prompt that will not change. In the case of this host, you'll want to look for the word 'login'. Your script might look something like this:
  25.  
  26. Dial Service "'My Host'"
  27. Wait for Text "'login'"
  28. Remark "--- wait another second to let"
  29. Remark "--- the rest of the prompt in"
  30. Wait Seconds "1"
  31. Send Text String "'bla bla bla^M'"
  32.  
  33. This is one step better than the Watch Me script. However, it is not foolproof. What if your host is really picky and may or may not show you a prompt when you log on. You might need to hit the carriage return a couple of times before that elusive prompt even shows up. This script will handle that situation:
  34.  
  35. Dial Service "'My Host'"
  36. Repeat
  37.   When Seconds Have Passed "1"
  38.     Send Text String "'^M'"
  39.   Or When Text Equals "'login'"
  40.   End When
  41. Until Text Equals "'login'"
  42. Remark "--- wait another second to let"
  43. Remark "--- the rest of the prompt in"
  44. Wait Seconds "1"
  45. Send Text String "'bla bla bla^M'"
  46.  
  47. This script contains a repeat loop that repeatedly checks for two conditions: has a second of time gone by, or have we seen a 'login' on the screen? If a second has gone by, the script sends out a carriage return, hoping to wake up the host. If the 'login' appears on the screen, the script leaves the repeat loop, waits a second for the rest of the prompt to come through, and sends out the login information.
  48.  
  49. WE'RE ON, ALMOST
  50.  
  51. OK, now you have successfully logged on, but you get a series of annoying '--more--' messages on your screen, to which you are supposed to respond by hitting the spacebar or carriage return. Problem is, you don't know how many of these you are going to get until you finally get the prompt you are looking for, in this case, the prompt 'happy:-)', which designates your final arrival to a place where you can get some real work done.
  52.  
  53. Here's a script that handles the problem. It looks for the '--more--' prompt, and if it sees it, send out a space. It does this until it sees the 'happy:-)' prompt.
  54.  
  55. Repeat
  56.   When Text Equals "'--more--'"
  57.     Send Text String "' '"
  58.     Remark "--- wait another second for good measure"
  59.     Wait Seconds "1"
  60.   Or When Text Equals "'happy:-)'"
  61.   End When
  62. Until Text Equals "'happy:-)'"
  63.  
  64. You're probably asking yourself, what is this "second for good measure" stuff? Well, when we send out the space, it's going to take a while for the host to echo it back to us. Since MicroPhone scripts go at a blazingly fast speed, we will make another run through the repeat loop, see the '--more--' prompt again (because the host hasn't sent us back the space yet) and promptly (pun intended) send out another space. We'll probably end up doing this several hundred times, flooding the poor host with spaces before it gets a chance to send us back the space we sent it. By placing a Wait Seconds after the Send Text String, we give the host enough time to process the space and echo it back, ensuring us that we won't see the same '--more--' prompt again.
  65.  
  66. Now, you are saying, why didn't we just use the "When Text In Stream Is" command? Doesn't it prevent this problem? Yes, it does, and here's the same script using When Text In Stream Is:
  67.  
  68. Repeat
  69.   When Text In Stream Is "'--more--'"
  70.     Send Text String "' '"
  71.   Or When Text Equals "'happy:-)'"
  72.   End When
  73. Until Text Equals "'happy:-)'"
  74.  
  75. The advantage of using When Text Equals and the Wait Seconds commands is that we prevent ourselves from being in a tight loop, allowing text to flow into MicroPhone's terminal window faster. The Wait Seconds command allows as much text to flow into the terminal window as possible in the given number of seconds, without evaluating each character as it comes through.
  76.  
  77. If we have a tight loop like the last example, MicroPhone has to go through the when loop for each and every character that passes through the serial port, which takes a lot of processing time. By sending out a space character and waiting a second, we allow a second's worth of characters to get through without evaluating them. We aren't interested in evaluating them because we know that a lot of text is going to come through before we see another '--more--' prompt.
  78.  
  79. So, why can't we use the "When Text In Stream Is" along with a Wait Seconds command? Because we might get a '--more--' prompt before a second has past, which the "When Text In Stream Is" command will not pick up. "When Text In Stream Is" will only process characters as they come through the serial port. Once they are on the screen, even if the cursor is to the very right of the characters, it is too late for "When Text In Stream Is" to work. However, the "When Text Equals" command will pick these characters up.